package com.control.servlet;

import com.dao.BlogDao;
import com.model.Blog;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by jinyb on 2017/4/11.
 */
public class BlogListServlet extends HttpServlet {
    //这里调用的
    BlogDao blogDao = new BlogDao();
    @Override
    public void init() throws ServletException {
        super.init();
//        blogDao = new BlogDao();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //这里是博客请求的入口。 /blogs.do
        System.out.print("123");
        List<Blog> blogs = blogDao.getAllBlogs();
        req.setAttribute("blogs", blogs);

        //这里跳转到一个jsp的界面
        RequestDispatcher dispatcher = req.getRequestDispatcher("/jsp/BlogList.jsp");
        dispatcher.forward(req, resp);


    }

   /* public List<Blog> getAllBlog() {
        List<Blog> blogs = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Blog blog = new Blog();
            blog.setContent("this is a good test");
            blog.setTitleName("this is a good test");

            blogs.add(blog);
        }
        return blogs;
    }*/
}
